package com.rc.saas.payment.wxpay.config;

import com.rc.saas.mini.model.tenant.Tenant;
import com.rc.saas.mini.model.tenant.TenantPayment;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * Created by sven on 2017/7/5.
 */
public class WxPayConfigImpl implements WXPayConfig {
    // 微信APP支付商户号(由申请APP支付时分配)
    private String mch_id;
    private String appid;
    //key为APP分配的商户平台设置的密钥key
    private String key;
    //微信支付后端回调通知地址
    //final String notifyUrl = "http://119.23.35.158:8181/wxpay/wxPayNotify";

    //微信支付接口中，涉及资金回滚的接口会使用到商户证书，包括退款、撤销接口，其它不需要
    private byte[] certData;

    @Override
    public String getAppID() {
        return appid;
    }

    @Override
    public String getMchID() {
        return mch_id;
    }

    @Override
    public String getKey() {
        return key;
    }

    /**
     * 使用支付信息初始化配置类
     *
     * @param tenantPayment
     */
    public WxPayConfigImpl(TenantPayment tenantPayment) {
        this.mch_id = tenantPayment.getMchid();
        this.appid = tenantPayment.getAppid();
        this.key = tenantPayment.getPrivateKey();
    }

    public WxPayConfigImpl(Tenant tenant) {
        this.mch_id = tenant.getWechatPayMchid();
        this.appid = tenant.getWechatAppid();
        this.key = tenant.getWechatPaySecret();
    }

    @Override
    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    @Override
    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    @Override
    public int getHttpReadTimeoutMs() {
        return 10000;
    }
}
